1. /* sloplus.cpp by K.Tsuru */
  2. // function ID = 201 DARDIX, BRADIX
  3. /**********************
  4. SLong class
  5. operator+() return m+n
  6. ***********************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. static const char* func = "SL +";
  11. SLong operator+(const SLong& m, const SLong& n) {
  12. if( m.Type() != n.Type() ) m.SetError(m.RADIX_ERR, func, 201);
  13. int s = m.Sign(201) * n.Sign(201);
  14. if( !s ){ //One of m and n is zero.
  15. if( m.Sign() == 0 ) return n;
  16. else return m;
  17. } else if ( s > 0 ){ //same sign
  18. SLong t;
  19. //It lets m >= n. See DDMult().
  20. if( m.aHead < n.aHead ) return LLAdd(n, m);
  21. return LLAdd(m, n); //sign is same as that of m(setted in LLAdd())
  22. } else { //diffrent sign
  23. SLong r(m.Type(), 0);
  24. int c = LLCompare(m, n);
  25. // m + n = m -(-n) = n-(-m)
  26. if(c > 0){
  27. r = n; r.ChangeSign(201); // r = -n
  28. return LLSub(m, r); // m > n
  29. }
  30. if(c){
  31. r = m; r.ChangeSign(201); // r = -m
  32. return LLSub(n, r); // m < n
  33. }
  34. r.SetZero();
  35. return r; // c = 0 : m = n
  36. }
  37. }

sloplus.cpp : last modifiled at 2015/11/27 14:24:50(1,053 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).